import format from "../../module/format";
import sessionModule from "../../module/sessionStorage";
export default {
  getHeadersOptions(state) {
    // 获取页头Options列表
    return state.layout.header.options.list.map((item) => {
      item.showTitle = item.showTitle ?? false;
      item.disable = item.disable ?? false;
      return item;
    });
  },
  // 获取用户信息
  getUserInfo(state) {
    let userInfo = {};
    let StoreinfoKeys = Object.keys(state.userInfo);
    if (StoreinfoKeys.length) {
      userInfo = state.userInfo;
    } else {
      userInfo = sessionModule.get("TardeUserInfo");
    }
    return userInfo;
  },

  // 获取所有设置列表
  getSettingList(state) {
    let setting = {};
    for (let key of Object.keys(state.layout)) {
      setting[key] = state.layout[key].setting || {};
    }
    return setting;
  },
  // 获取所有主题配置信息
  getThemeAllList(state) {
    return state.theme.list;
  },
  // 获取当前主题配置信息
  getCurrentTheme(state) {
    let current = state.theme.current;
    return state.theme.list[current].style;
  },
  // 获取当前菜单侧边栏状态
  getCurrentNavigatorShow(state) {
    return state.navigatorShow;
  },
  // 获取当前图标侧边ID
  getCurrentIconNavigatorId(state) {
    return state.currentIconNavigatorId;
  },
  getCurrentNavigatorId(state) {
    return state.currentNavigatorId;
  },

  // 获取图标导航菜单列表 / 获取树形导航菜单
  handleIconNavigatorList(state) {
    let list = state.navigatorMenuList;
    return list.filter((i) => i.meta.pid == null);
  },
  // 根据导航数据返回VueRouter数据
  handleVueRouterList(state) {
    let list = state.navigatorMenuList;
    return format.ArrayFormatVueRouter(list);
  },
  // 侧边栏顶部当前选择的菜单名称
  currentSelectIconNavigatorName(state) {
    let currentID = state.currentIconNavigatorId;
    let list = state.navigatorMenuList;
    if (currentID) {
      return list.find((i) => i.meta.id == currentID).meta.title;
    } else {
      return "所有菜单";
    }
  },
  navigatorInfo(state) {
    let currentid = state.currentIconNavigatorId;
    let list = state.navigatorMenuList;
    return {
      currentid,
      handleVueRouterList: format.ArrayFormatVueRouter(list),
      originList: list,
      navigatorShow: state.navigatorShow,
      currentTitle:
        list.find((i) => i.meta.id == currentid).meta.title ?? "所有菜单",
    };
  },
  // 返回存储的导航原数据
  getOriginNavigator(state) {
    return state.navigatorMenuList;
  },
  // 返回存储的导航原数据
  getNavigatorMenuList(state) {
    return state.navigatorMenuList;
  },
  // 获取配置项信息
  getGlobalSetting(state) {
    return state.setting;
  },
  // 获取系统设置信息
  getCustomList(state) {
    let list = [];
    if (state.customList.length) {
      list = state.customList;
    } else {
      // list = [];
      list = sessionModule.get("TardeCustomListData");
    }
    return list;
  },
};
